package com.gin.kotlin.no_gay_alliance.adapter.ban

import android.content.Context
import android.view.View
import com.gin.kotlin.no_gay_alliance.app.App
import com.gin.kotlin.no_gay_alliance.base.AbstractBindingRecyclerViewAdapter
import com.gin.kotlin.no_gay_alliance.base.MyHandler
import com.gin.kotlin.no_gay_alliance.database.entity.BanKeyword
import com.gin.kotlin.no_gay_alliance.databinding.ItemBanKeywordBinding

class BanKeywordAdapter(context: Context, handler: MyHandler) : AbstractBindingRecyclerViewAdapter<ItemBanKeywordBinding, BanKeyword>(context, handler,false), View.OnClickListener {
    override fun onBindViewHolder(holder: ViewHolder<ItemBanKeywordBinding>, position: Int, b: ItemBanKeywordBinding, dataModel: BanKeyword) {
        b.tvKeyword.text = dataModel.value
        b.ivDelete.tag = data.indexOf(dataModel)
        b.ivDelete.setOnClickListener(this)
    }

    override fun onClick(v: View?) {
        val index = v?.tag as? Int ?: return
        App.INSTANCE.database.banKeywordDao().del(data[index].value)
        removeData(index)
    }
}
